package com.yiba.vpn.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class AcordingTxtCreatSqlUtil {

    /**
     * 读取txt文件的内容
     * @param file 想要读取的文件对象
     * @return 返回文件内容
     */
    public static String txt2String(File file){
        StringBuilder result = new StringBuilder();
        int countlines = 0 ;
        try{
            BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
            String s = null;
            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                if(countlines ==0){
                    result.append("INSERT INTO `t_vpn_proxy_domain` ( `proxy_domain` ) VALUES");
                    s="'"+s.trim()+"'";
                    result.append("( "+s+" )");
                }else{
                    s="'"+s.trim()+"'";
                    result.append(",( "+s+" )");
                }
                countlines++;

            }
            result.append(";");
            br.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }

    public static void main(String[] args){
        File file = new File("D:/ip.txt");
        System.out.println(txt2String(file));
    }
}
